<template>
  <el-dialog title="患者基本信息" :close-on-click-modal="false" :visible.sync="visible" fullscreen center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form ref="searchForm" :model="dataForm" label-width="100px">
      <el-row class="bg-row">
        <el-col :span="3">
          <el-form-item label="姓名:">
            <el-input v-model="dataForm.presonName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="性别:">
            <el-input v-if="dataForm.gender == 0" value="男" readonly></el-input>
            <el-input v-if="dataForm.gender == 1" value="女" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="年龄:">
            <el-input v-model="dataForm.age" readonly>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="手机号:">
            <el-input v-model="dataForm.telPhone" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="门诊号:">
            <el-input v-model="dataForm.birthDay" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="患者ID:">
            <el-input v-model="dataForm.id" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="4">
          <el-form-item label="就诊时间:">
            <el-input v-model="dataForm.checkTime" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="就诊科室:">
            <el-input v-model="dataForm.deptName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="就诊医生:">
            <el-input v-model="dataForm.telPhone" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="诊断:">
            <el-input v-model="dataForm.birthWeight" readonly>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">
        <el-col :span="4">
          <el-form-item label="过敏史:">
            <el-input v-model="dataForm.address" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="处方单号:">
            <el-input v-model="dataForm.presBillId" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="bg-row">

      </el-row>
    </el-form>
    <el-divider content-position="left">处方信息</el-divider>
    <el-link :href="printUrl" target="_blank" type="primary" style="float: right;margin-bottom: 15px;"><el-button size="mini" type="primary" @click="getWorkParams" v-prevent-re-click>打印普通处方</el-button></el-link>
<!--    <el-button type="primary" @click="getWorkParams">打印普通处方</el-button>-->
    <div class="avue-crud">
      <el-table :data="dataList" border>
        <el-table-column prop="medicineName" header-align="center" align="center" label="药品名称">
        </el-table-column>
        <el-table-column prop="usages" header-align="center" align="center" label="用法">
        </el-table-column>
        <el-table-column prop="usageLocation" header-align="center" align="center" label="用药部位">
        </el-table-column>
        <el-table-column prop="metering" header-align="center" align="center" label="单次剂量">
        </el-table-column>
        <el-table-column prop="frequency" header-align="center" align="center" label="频次">
        </el-table-column>
        <el-table-column prop="money" header-align="center" align="center" label="金额">
        </el-table-column>
        <el-table-column header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" icon="el-icon-edit" @click="getWorkParams">打印标签</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="unregularRecipelHandle">不合理处方</el-button>
      <el-button type="primary" @click="takeMedicineHandle(dataForm.id)">系统发药</el-button>
    </span>

    <!-- 弹窗, 系统发药 -->
    <table-form v-if="takeMedicineVisible" ref="takeMedicine"></table-form>
    <!-- 不合理处方 -->
    <unregular-recipel v-if="unregularVisible" ref="unregularDialog"></unregular-recipel>
  </el-dialog>

</template>

<script>
  import { getPrescriptionObj, addEimsOutpatientPrescriptionObj, putEimsOutpatientPrescriptionObj } from '@/api/eims/prescription'
  import TableForm from './out-medicine'
  import { filterParams } from '@/util/tools'
  import UnregularRecipel from './components/UnregularRecipel'
  let params = '/HairMedicine/reasonable.cpt'
  export default {
    data() {
      return {
        takeMedicineVisible: false,
        unregularVisible: false,
          printUrl: '',
        dataList: [],
        visible: false,
        dataForm: {
          id: 0,
          presBillId: '',
          name: '',
          status: '',
          medicineStatus: '',
          presonName: '',
          presonId: ''
        },
        dataRule: {
          presBillId: [{ required: true, message: '处方单号不能为空', trigger: 'blur' }],
          name: [{ required: true, message: '药品名称不能为空', trigger: 'blur' }],
          status: [{ required: true, message: '处方状态(1-合格处方,2-不合格处方)不能为空', trigger: 'blur' }],
          medicineStatus: [{ required: true, message: '发药状态(1-未发药,2-以发药)不能为空', trigger: 'blur' }],
          presonName: [{ required: true, message: '患者姓名不能为空', trigger: 'blur' }],
          presonId: [{ required: true, message: '患者ID不能为空', trigger: 'blur' }]
        }
      }
    },
    components: {
      TableForm,
      UnregularRecipel
    },
    methods: {
      init(id, name) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          if (this.dataForm.id) {
            getPrescriptionObj(this.dataForm.id).then(response => {
              this.dataForm = response.data.data
              this.dataList = response.data.data.detailList
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
              putEimsOutpatientPrescriptionObj(this.dataForm).then(data => {
                this.$message.success('修改成功')
                this.visible = false
                this.$emit('refreshDataList')
              });
            } else {
              addEimsOutpatientPrescriptionObj(this.dataForm).then(data => {
                this.$message.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList')
              })
            }
          }
        })
      },
        getWorkParams() {
            console.log("11111")
            params = '/HairMedicine/reasonable.cpt'
            let data = filterParams(this.dataForm.id)
            let parameter = ''
            for(let key in data){
                parameter += '&' + key + '=' + this.dataForm[key]
            }
            // let parameter = '&deptId='+this.dataForm.deptId + '&beginTime='+this.dataForm.beginTime+ '&endTime='+this.dataForm.endTime
            let frUrl = "http://localhost:8075/webroot/decision/view/report?viewlet=HairMedicine/reasonable.cpt"

            this.printUrl = frUrl
            //this.printUrl = this.bizData.printUrl + params + parameter
        },
      // 发药
      takeMedicineHandle(id) {
        this.takeMedicineVisible = true
        this.$nextTick(() => {
          this.$refs.takeMedicine.init(id)
        })
      },
      // 不合理处方
      unregularRecipelHandle(){
        this.unregularVisible = true
        this.$nextTick(() => {
          this.$refs.unregularDialog.init(this.dataForm.id)
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .unregular-recipel {
    position: fixed;
    right: 20px;
    bottom: 15%;
    font-size: 50px;
    color: #F56C6C;
  }
</style>
